function vali = getValidator( res, lab )

if nargin <2
    data = res;    
    vali.tp = data(1);
    vali.fp = data(2);
    vali.fn = data(3);
    vali.tn = data(4);
else
    th = 0.5;
    res = res(:);
    lab = lab(:);
    
    if(length(lab)~=length(res))
        disp('warning! size unmatch while predict');
        n = min(length(lab),length(res));
        lab = lab(1:n); res = res(1:n);
    end
    
    res = int8(res>th);    
    lab = int8(lab>th);
    vali.tp = sum( lab( res==1 ) );
    vali.fp = sum( res ) - vali.tp;
    vali.tn = sum( 1 - lab( res==0 ) );
    vali.fn = sum( 1 - res ) - vali.tn;
end

if 1 %smooth
    m_eps = 0.01;
    vali.tp = vali.tp + m_eps;
    vali.fp = vali.fp + m_eps;
    vali.fn = vali.fn + m_eps;
    vali.tn = vali.tn + m_eps;
end

vali.precision = vali.tp / (vali.tp+ vali.fp);
vali.recall = vali.tp / (vali.tp + vali.fn );
vali.F1 = vali.precision * 2 * vali.recall /( vali.recall + vali.precision);
vali.ZeroOne = (vali.tp + vali.tn ) / (vali.tp + vali.fp + vali.fn + vali.tn );